<?php

$id = $_SESSION['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$newpassword = $_POST['newpassword'];
$repeatnewpassword = $_POST['repeatnewpassword'];
if ($newpassword != "") {
    if ($newpassword != $repeatnewpassword) {
        print "<script language='javascript'>
        alert('The new password does not match with the repeated one.');
        history.back();';
        </script>";
    } else {
        $password = passwordmd5($newpassword);
        $sql = "UPDATE `user` SET `name` = '$name', `email` = '$email', `password` = '$password' WHERE `id` = '$id';";
    }
} else {
    $sql = "UPDATE `user` SET `name` = '$name', `email` = '$email' WHERE `id` = '$id';";
}
$result = mysql_query($sql);

$_SESSION['email'] = $email;
$_SESSION['name'] = $name;

print "<script language='javascript'>
        alert('Your data was updated successfully.');
        window.location.href='./';
        </script>";
?>
